var t = function(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}(require("../../until/storage")), a = getApp(), e = null;

Page({
    data: {
        videoAd: a.globalData.config.adConfig.videoAd,
        detailGridAd: a.globalData.config.adConfig.detailGridAd,
        likeList: [],
        tabArr: [ {
            key: 1,
            value: "在线播放",
            select: 1
        }, {
            key: 2,
            value: "浏览器中播放",
            select: 0
        }, {
            key: 3,
            value: "下载视频",
            select: 0
        } ],
        currentTab: 0,
        isLive: !1,
        id: "",
        detail: {},
        link: "",
        list: [],
        isShow: !1,
        descIsShow: !1,
        collIsShow: !1,
        louck_share: !1,
        louck_num: null,
        expires_timeOut: null,
        localtionAppid: "",
        onShowFlag: !1
    },
    getCollected: function() {
        var t = wx.getStorageSync("_collect");
        if (t) {
            var a = t[this.data.id];
            this.setData({
                collIsShow: a
            });
        } else {
            var e = {};
            wx.setStorageSync("_collect", e);
        }
    },
    college: function() {
        var t = wx.getStorageSync("_collect"), a = t[this.data.id];
        a = !a, t[this.data.id] = a, !1 === a && delete t[this.data.id], wx.setStorageSync("_collect", t), 
        this.setData({
            collIsShow: a
        });
    },
    desc: function() {
        console.log("xxxx"), this.setData({
            descIsShow: !this.data.descIsShow
        });
    },
    previewImage: function(t) {
        var a = t.target.dataset.src;
        wx.previewImage({
            current: a,
            urls: [ a ]
        });
    },
    _tab: function(t) {
        var a = t.currentTarget.dataset.index;
        if (this.data.currentTab === a) return !1;
        this.setData({
            currentTab: a,
            index: a
        }), 0 == a ? this.setData({
            list: this.data.detail.play_m3u8
        }) : 1 == a ? this.setData({
            list: this.data.detail.play_zuidaall
        }) : this.setData({
            list: this.data.detail.download
        });
    },
    show: function() {
        this.setData({
            isShow: !0
        });
    },
    hide: function() {
        this.setData({
            isShow: !1
        });
    },
    onLoad: function(t) {
        this.setData({
            id: t.id
        }), this.getCollected(), console.log("getdetail的id", this.data.id);
        var e = this;
        wx.request({
            url: "https://www.120kg.xyz/getDetail",
            data: {
                id: e.data.id
            },
            method: "POST",
            success: function(t) {
                var a = t.data.data;
                a.play_m3u8 = a.play_m3u8.split(","), a.play_zuidaall = a.play_zuidaall.split(","), 
                a.download = a.download.split(",");
                var o = [];
                a.play_m3u8.forEach(function(t, a, e) {
                    var i = {};
                    i.title = t.split("$")[0], i.href = t.split("$")[1], o.push(i);
                }), a.play_m3u8 = o, a.analysisUrl = a.analysisUrl;
                var i = [];
                a.download.forEach(function(t, a, e) {
                    var o = {};
                    o.title = t.split("$")[0], o.href = t.split("$")[1], i.push(o);
                }), a.download = i, e.setData({
                    detail: a,
                    list: a.play_m3u8
                }), e.like(e.data.detail.movieType);
            }
        });
        var o = null;
        wx.createInterstitialAd && ((o = wx.createInterstitialAd({
            adUnitId: a.globalData.config.adConfig.detailInterstitialAd
        })).onLoad(function() {}), o.onError(function(t) {}), o.onClose(function() {})), 
        setTimeout(function() {
            o.show().catch(function(t) {
                console.error(t);
            });
        }, 2e3), this.setRewardedVideoAd();
    },
    like: function(t) {
        var a = this;
        wx.request({
            url: "https://www.120kg.xyz/like",
            data: {
                type: t
            },
            method: "POST",
            success: function(t) {
                console.log("like", t.data.data), a.setData({
                    likeList: t.data.data
                });
            }
        });
    },
    setRewardedVideoAd: function() {
        var t = this;
        wx.createRewardedVideoAd && ((e = wx.createRewardedVideoAd({
            adUnitId: a.globalData.config.adConfig.detailRewardedVideoAd
        })).onLoad(function() {
            console.log("拉取激励广告成功");
        }), e.onError(function(t) {
            console.log("拉取激励广告失败");
        }), e.onClose(function(a) {
            a && a.isEnded ? (console.log("激励广告加载完成"), t.setClipboardData()) : (console.log("激励广告被强制关闭"), 
            wx.showToast({
                title: "没有获得vip特权哦！",
                icon: "none",
                duration: 3e3
            }));
        }));
    },
    play: function(t) {
        var a = t.currentTarget.dataset, e = a.href, o = a.click, i = this;
        if ("onlive" == o) wx.navigateToMiniProgram({
            appId: this.data.localtionAppid,
            path: "/pages/live/index",
            extraData: {
                href: e
            },
            envVersion: "release",
            success: function(t) {
                i.setData({
                    onShowFlag: !0
                });
            }
        }); else {
            var n = "";
            n = "live" == o ? "复制链接成功 请在浏览器中打开观看" : "复制链接成功 请在迅雷打开下载";
            wx.setClipboardData({
                data: e,
                success: function(t) {
                    wx.showToast({
                        title: n,
                        icon: "none",
                        duration: 3e3
                    });
                }
            });
        }
    },
    onReady: function() {},
    copyWx: function() {
        e && e.show().catch(function() {
            e.load().then(function() {
                return e.show();
            }).catch(function(t) {
                console.log("激励视频 广告显示失败");
            });
        });
    },
    setClipboardData: function() {
        wx.setClipboardData({
            data: "huangshaonan315",
            success: function(t) {
                wx.hideToast(), wx.showModal({
                    title: "微信号已复制成功",
                    content: "微信点击'添加好友' 长按粘贴即可",
                    showCancel: !1,
                    confirmText: "知道了",
                    success: function(t) {
                        t.confirm ? console.log("用户点击确定") : t.cancel && console.log("用户点击取消");
                    }
                });
            }
        });
    },
    scrollTo: function(t) {
        var a = t.currentTarget.dataset.cur;
        wx.createSelectorQuery().select(".dark").boundingClientRect(function(t) {
            var a = t.top;
            wx.pageScrollTo({
                scrollTop: a
            });
        }).exec(), this.setData({
            currentTab: a
        });
    },
    onShow: function() {
        if (this.data.onShowFlag) this.setData({
            onShowFlag: !1
        }); else {
            var e = this, o = a.globalData.config, i = o.showVersion, n = o.sessionVersion, l = t.default.get("localShareNum");
            wx.request({
                url: "https://www.120kg.xyz/wxMovieVersion",
                success: function(a) {
                    if (i < +a.data[n].version) {
                        if (e.setData({
                            isLive: !0,
                            localtionAppid: a.data[n].localtionAppid,
                            louck_num: +a.data[n].louckConfig.louck_num || 3,
                            expires_timeOut: +a.data[n].louckConfig.expires_timeOut || 1440
                        }), a.data[n].louckConfig.louckStatus) if (l) {
                            var o = l += 1;
                            3 === l && e.setData({
                                louck_share: !0
                            }), t.default.set("localShareNum", o);
                        } else t.default.set("localShareNum", 1), wx.setStorageSync("localShareNum__expires__", Date.now() + 6e4 * e.data.expires_timeOut);
                    } else e.setData({
                        isLive: !1
                    });
                }
            });
        }
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        var t = this.data.detail, a = (t.picUrl, t.name);
        return this.setData({
            louck_share: !1,
            onShowFlag: !0
        }), {
            title: "[有人@你] 邀请您一起看" + a,
            path: "pages/getDetail/index?id=" + this.data.id,
            imageUrl: "",
            success: function(t) {}
        };
    }
});